import os
import time
import sys
import json
import requests

sys.path.append(
    os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "imlfapi")
)

from db import GraphsTB
from constants import GRAPHTYPE

base_url = "http://localhost:8000/imlf/api/v1/graphs/{graph_id}"

headers = {
    # "token": "eyJhbGciOiJIUzUxMiIsImlhdCI6MTYyNjA4NTkxMiwiZXhwIjoxNjU3NjIxOTEyfQ.eyJuYW1lIjoi6YOR5rC05riFIn0.Z-Ex06NpzkSYbNf8liVuXh9qB92LXyxDsmfW8Dx60UvFY95IJlZmEa_UoxRyiUF0pNBAJVcpKFjNBluQE2OKaA",
}
graphs = GraphsTB.find(
    username=("not in", ["郑水清", "wujiedong"]),
    category=GRAPHTYPE.TRAIN,
)

graph_id_list = [i["id"] for i in graphs]


def run():
    """删除"""
    for num, graph_id in enumerate(graph_id_list):
        print("%s / %s" % (num, len(graph_id_list)))
        url = base_url.format(graph_id=graph_id)
        res = requests.delete(url, headers=headers)
        content = json.loads(res.content)
        print(content)
        time.sleep(0.1)


if __name__ == "__main__":
    run()
